package gnippets.domain

/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *  <p>The gniplet class represents a single element of code within a snippet 
 *  class.  This allows snippets to be more complex, possibly across multiple
 *  files or categories (Groovy, SQL, XML).</p>
 *
 *  <p>Typically though a snippet would only include one fragment.</p>
 *
 *  @author <a href='mailto:kouphax@gmail.com'>James Hughes</a>
 */
class Gniplet {
    
    /**
     *  A description of what this fragment is trying to achieve
     */
    String description
    
    /**
     *  The actual code fragment content
     */
    String codeSnippet
    
    /**
     *  The format the code is written in e.g. Java, Groovy, SQL...
     */     
    String programmingLanguage 
    
    /**
     *  Injected service for RefCode validation
     */
    def refCodeService

    static belongsTo = [gnippet:Gnippet]
    
    static constraints = {         
        description(nullable:false, blank:false)
        codeSnippet(nullable:false, blank:false)
        programmingLanguage(
            validator : { value, source ->
                /* validate entry against injected service */
                source.refCodeService.validate("language", value) 
            }
        )
    }
}
